package com.zombie.util;

import java.text.SimpleDateFormat;
import java.util.Random;

import com.badlogic.gdx.graphics.g2d.tiled.TiledMap;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;

public class Utils {
	public static Random rnd = new Random();
    static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd hh mm ss a");

//	public static Path correctPath(Path p){
//		if (p == null)
//			return null;
//		if (p.getLength() == 0)
//			return null;
//		ArrayList<Step> steps = new ArrayList<Step>();
//		steps.add(p.getStep(0));
//		for(int i =0;i< p.getLength();i++){
//			if (!steps.contains(p.getStep(i))){
//				if (steps.get(steps.size()-1).getX() == p.getStep(i).getX() ||
//						steps.get(steps.size()-1).getY() == p.getStep(i).getY()){
//				} else {
//					steps.add(p.getStep(i-1));
//				}
//			}		
//		}
//		steps.add(p.getStep(p.getLength()-1));
//		Path pp = new Path();
//		for(Step s : steps)
//			pp.appendStep(s.getX(), s.getY());
//		return pp;
//	}
	
    
//	public static void screenShot() {
//		try	{
//			Image target = new Image(SCREEN_WIDTH, SCREEN_HEIGHT);
//			StateGame.game.getContainer().getGraphics().copyArea(target, 0, 0);
//			String name = "screen_"+formatter.format(Calendar.getInstance().getTime())+".png";
//			ImageOut.write(target.getFlippedCopy(false, false), name, false);
//			target.destroy();
//		} catch (SlickException e) {
//			e.printStackTrace();
//		}
//	}


	public static int randomInt(int min, int max) {
		int c = max - min;
		return min+rnd.nextInt(c);
	}

	
	public static int getLayerIndex(String name, TiledMap map){
		for (int i = 0; i < map.layers.size();i++)
			if (map.layers.get(i).name.equalsIgnoreCase(name))
				return i;
		return 0;
	}


	public static void beginShapeRenderer(ShapeRenderer shape,	ShapeType type) {
		if (shape.getCurrentType() != type){
			if (shape.getCurrentType() != null)
				shape.end();
			shape.begin(type);
		}
	}



}
